import baseService from "@/service/baseService";
import { IObject } from "@/types/interface";

/**
 * 权限/组织/角色/账号 等 Authority 模块 API 定义
 * - 统一使用中文 JSDoc 注释，描述接口用途、方法与路径
 */

/** 权限管理 API */
export const permissionApi = {
  /**
   * 获取当前用户的权限列表
   * GET /sys/menu/permissions
   */
  getUserPermissions: () => baseService.get("sys/menu/permissions"),

  /**
   * 获取当前用户的菜单导航信息
   * GET /sys/menu/nav
   */
  getMenuInfo: () => baseService.get("sys/menu/nav"),

  getUserInfo: () => baseService.get("sys/user/info")
};

/** 组织类型管理 API */
export const organizationTypeApi = {
  /**
   * 获取根组织类型列表
   * GET sys/organization/rootpage
   */
  getRootTypes: () => baseService.get("sys/organization/rootpage"),

  /**
   * 修改根组织类型
   * PUT sys/organization/rootorgan
   */
  updateRootType: (data: IObject) => baseService.put("sys/organization/rootorgan", data),

  /**
   * 查询组织类型权限（按角色 ID）
   * GET sys/role/{id}
   */
  getTypePermissions: (id: string) => baseService.get(`sys/role/${id}`)
};

/** 下级组织 */
export const organizationApi = {
  /**
   * 组织分页查询
   * GET sys/organization/page
   */
  getPage: (params: IObject) => baseService.get("sys/organization/page", params),

  /**
   * 新增组织
   * POST sys/organization
   */
  create: (data: IObject) => baseService.post("sys/organization", data),

  /**
   * 修改组织
   * PUT sys/organization
   */
  update: (data: IObject) => baseService.put("sys/organization", data),

  /**
   * 根据 ID 查询组织
   * GET sys/organization/{id}
   */
  getById: (id: string) => baseService.get(`sys/organization/${id}`),

};

/** 角色管理 API */
export const roleApi = {
  /**
   * 角色分页查询
   * GET sys/role/page
   */
  getPage: (params: IObject) => baseService.get("sys/role/page", params),

  /**
   * 角色新增时的菜单查询
   * GET sys/menu/select
   */
  getAddQuery: () => baseService.get("sys/menu/select"),

  /**
   * 新增角色
   * POST sys/role
   */
  create: (data: IObject) => baseService.post("sys/role", data),

  /**
   * 修改角色
   * PUT sys/role
   */
  update: (data: IObject) => baseService.put("sys/role", data),

  /**
   * 根据 ID 查询角色详情
   * GET sys/role/{id}
   */
  getById: (id: string) => baseService.get(`sys/role/${id}`),

  /**
   * 删除角色（支持批量）
   * DELETE sys/role 或 DELETE sys/role/{id}
   */
  delete: (ids: string[] | string) => {
    if (Array.isArray(ids)) {
      return baseService.delete("sys/role", { data: ids });
    } else {
      return baseService.delete(`sys/role/${ids}`, {});
    }
  },

  /**
   * 修改角色状态
   * PUT sys/role/status
   */
  updateStatus: (data: IObject) => baseService.put("sys/role/status", data),

  /**
   * 获取角色列表（无分页）
   * GET sys/role/list
   */
  getList: () => baseService.get("sys/role/list")
};

/** 账号管理 API */
export const accountApi = {
  /**
   * 新增账号
   * POST sys/user
   */
  create: (data: IObject) => baseService.post("sys/user", data),

  /**
   * 修改账号
   * PUT sys/user
   */
  update: (data: IObject) => baseService.put("sys/user", data),

  /**
   * 账号禁用/启用
   * PUT sys/user/enable
   */
  updateStatus: (data: IObject) => baseService.put("sys/user/enable", data),

  /**
   * 密码重置
   * PUT sys/user/resetpass
   */
  resetPassword: (data: IObject) => baseService.put("sys/user/resetpass", data),

  /**
   * 修改密码
   * PUT sys/user/password
   */
  updatePassword: (data: IObject) => baseService.put("sys/user/password", data),

  /**
   * 账号分页查询
   * GET sys/user/page
   */
  getPage: (params: IObject) => baseService.get("sys/user/page", params),

  /**
   * 根据 ID 查询账号
   * GET sys/user/{id}
   */
  getById: (id: string) => baseService.get(`sys/user/${id}`),

  /**
   * 删除账号
   * DELETE sys/user/{id}
   */
  delete: (id: string) => baseService.delete(`sys/user/${id}`, {})
};

/** 客户端管理 API */
export const clientApi = {
  /**
   * 客户端分页查询
   * GET sys/clients/page
   */
  getPage: (params: IObject) => baseService.get("sys/clients/page", params),

  /**
   * 更新客户端
   * PUT sys/clients/update
   */
  update: (data: IObject) => baseService.put("sys/clients/update", data),

  /**
   * 获取客户端信息
   * GET sys/clients/{id}
   */
  getInfo: (id: string) => baseService.get(`sys/clients/${id}`)
};
